package controller.admin.setmeal;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import model.DTO.SetmealEditDTO;
import model.DTO.SetmealPageDTO;
import model.VO.SetmealPageVO;
import service.Impl.SetmealServiceImpl;
import util.GetJsonUtil;
import util.ResultUtil;

import java.io.IOException;
@WebServlet("/admin/setmeal/page")
public class SetmealPageController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        SetmealPageDTO spD= (SetmealPageDTO) GetJsonUtil.get(req,new SetmealEditDTO());
        int page= Integer.parseInt(req.getParameter("page"));
        int pageSize= Integer.parseInt(req.getParameter("pageSize"));
        String name=req.getParameter("name");
        String categoryIdStr=req.getParameter("categoryId");
        Integer categoryId=null;
        if (categoryIdStr != null && !categoryIdStr.isEmpty()) {
            categoryId = Integer.parseInt(categoryIdStr);
        }
        String statusStr=req.getParameter("status");
        Integer status=null;
        if (statusStr != null && !statusStr.isEmpty()) {
            status = Integer.parseInt(statusStr);
        }

        SetmealPageDTO spD=new SetmealPageDTO();
        spD.setPage(page);
        spD.setPageSize(pageSize);
        spD.setCategoryId(categoryId);
        spD.setName(name);
        spD.setStatus(status);

        SetmealServiceImpl ss=new SetmealServiceImpl();
        SetmealPageVO spV=ss.page(spD);

        String json= ResultUtil.getJSON(spV);
        resp.getWriter().println(json);
    }
}
